package com.devicemantra.coordinate;

import com.devicemantra.coordinate.dataobjects.*;
import java.util.*;
import java.util.logging.Level;
import java.util.logging.Logger;

import java.io.IOException;
import javax.servlet.http.*;

import com.devicemantra.coordinate.dataobjects.CDepartmentFactory;
import com.devicemantra.coordinate.ds.tests.ViewDepartment;

@SuppressWarnings("serial")
public class AdminController extends HttpServlet 
{
	private static final Logger log = Logger.getLogger(AdminController.class.getName());
	public void AddDepartments(HttpServletRequest req)
	{
		List<CDepartment> lListDepts = CDepartmentFactory.getAllDepartments();
		req.setAttribute("DEPT_LIST", lListDepts);
	}
	
	public void AddStates(HttpServletRequest req)
	{
		List<CState> lListStates = CStateFactory.getAllStates();
		req.setAttribute("STATE_LIST", lListStates);
	}
	
	
	
	public void Forward(HttpServletRequest req, HttpServletResponse resp)
	{
		String lForwardUrl = "";
		String lCategoryId = req.getParameter("id"); /* user ,state , department, sub dept etc */
		String lReqType = req.getParameter("req_type"); /* add , modify, delete */
		if(lCategoryId.equals("department"))
		{
				AddDepartments(req);
				lForwardUrl = "/modules/administration/department.jsp";
			
		}
		else if(lCategoryId.equals("states"))
		{
				AddStates(req);
				lForwardUrl = "/modules/administration/states.jsp";
			
			
		}
		else if(lCategoryId.equals("subdepartment"))
		{
			
				AddDepartments(req);
				lForwardUrl = "/modules/administration/subdepartment.jsp";
			
		}
		else if(lCategoryId.equals("users"))
		{
			
				AddDepartments(req);
				lForwardUrl = "/modules/administration/users.jsp";
			
		}
				
		try
		{
			System.out.println("[Forwarding] to " + lForwardUrl);
			req.getRequestDispatcher(lForwardUrl).forward(req, resp);
		}catch(Exception e ) {}
		
	} 
	
	
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException 
	{
		try
		{
			 log.log(Level.INFO, "Admin controller logged it");
			System.out.println("Testing loggingSaas");
			//resp.getOutputStream().print("Testing AdminController logging");
			//resp.flushBuffer(); 
			Forward(req,resp);
		}catch(Exception e) {}
	}
}
